package leetcode;

/**
 * Created with IntelliJ IDEA.
 * Description:剑指 Offer II 024. 反转链表
 * User: 东莞呵呵
 * Date:2022-07-19
 * Time:15:56
 */
public class TestDemo7 {
    public ListNode reverseList(ListNode head) {
        ListNode cur=head.next;
        ListNode prev=head;
        while(cur.next!=null){
            ListNode curNext=cur.next;
            cur.next=prev;
            prev=cur;
            cur=curNext;
        }
        head.next=null;
        return prev;
    }
    class ListNode {
     int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }
}
